import 'dart:math';

import 'package:clipboard/clipboard.dart';
import 'package:zootix/store/zt_ticket.store.dart';
import 'package:zootix/util/zt_snack_bar.util.dart';
import 'package:crypto/crypto.dart';
import 'dart:convert';

class ZtCommonUtil {
  static String generateMd5(String input) {
    List<int> bytes = utf8.encode(input); // 将字符串转换为字节码
    Digest md5Hash = md5.convert(bytes); // 对字节码进行MD5加密
    String encryptedString = md5Hash.toString(); // 获取加密后的字符串
    return encryptedString;
  }

  static String generateTicketNumber() {
    Random random = Random();

    int randomTwoDigitNumber = random.nextInt(99);
    String twoDigitNumber = randomTwoDigitNumber.toString().padLeft(2, '0');

    // 格式化数字串
    String formattedNumber =
        '${random.nextInt(9999999).toString().padLeft(7, '0')}${random.nextInt(9999999).toString().padLeft(7, '0')}-$twoDigitNumber';

    return formattedNumber;
  }

  static String firstUppercase(String text) {
    return '${text[0].toUpperCase()}${text.substring(1)}';
  }

  static Future<void> doCopy(String text) async {
    await FlutterClipboard.copy(text);
    await ZtSnackBarUtil().success('Copy Successfully.');
  }
}
